<template>
  <base-breadcrumb :title="$route.meta.title" :breadcrumb="!isAudit">
    <!-- 新增清单或超额合同审批 -->
    <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }" :rules="editModel != 0 ? rules : {}">
      <a-spin :spinning="loading">
        <!-- 表格 -->
        <a-card :bordered="false">
          <title-name title="基础信息"></title-name>
          <custom-form :isEmit="false" :formList="formList" :form="form" :editModel="editModel == 0 ? '' : ''"
                        @select="selectOrg"
                        @getProjectInfo="getProjectInfo"> </custom-form>
        </a-card>
        <a-card v-if="editModel == 0 && form.type == 2">
          <title-name title="会签内容"></title-name>
          <custom-form :isEmit="false" :formList="formListHuiqian" :form="form" :editModel="''"> </custom-form>
        </a-card>
        <a-card v-if="form.type == 0 || form.type == 1" :bordered="false">
          <title-name title="新增清单"></title-name>
          <template v-if="editModel != 0">
            <a-button class="mb12" type="primary" icon="plus" @click="handleManage('2')">新增</a-button>
            <ExcelImportButton class="ml12" ref="excelImportButton" icon="import" button-text="导入" @handleSubmit="handleImport" />
            <!-- 下载模板 -->
            <ExportExcel class="ml12" ref="exportExcel" :export-list="exportList" icon="export" :file-name="'新增清单模板.xlsx'" button-text="下载模板" />
          </template>
          <!-- 表格 -->
          <s-table
            bordered
            ref="table"
            tableLayout="fixed"
            size="default"
            rowKey="id"
            :columns="editModel != '0' ? columns : columnsLook"
            :data="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
            :showPagination="false"
          >
            <template slot="operation" slot-scope="text, record, index">
              <a @click="handleManage('0', record)">查看</a>
              <!-- 编辑 -->
              <span v-if="editModel != 0">
                <a-divider type="vertical" />
                <a @click="handleManage('1', record)">编辑</a>
              </span>
              <!-- 删除 -->
              <span v-if="editModel != 0">
                <a-divider type="vertical"></a-divider>
                <a-popconfirm title="确定要删除?" @confirm="() => handleRemove(record, index)">
                  <a>删除</a>
                </a-popconfirm>
              </span>
            </template>
            <!-- <template v-if="editModel != 0" slot="footer"> <a @click="addLine">添加行</a> </template> -->
          </s-table>
        </a-card>

        <!-- 页脚操作栏 -->
        <div class="btn_box page-btn-right-top" v-if="editModel != 0 && !isConsultation">
          <a-button class="button_right" v-if="form.auditStatus == 5" type="primary" :loading="loadingBtn.REJECTED" @click="handleSubmit('REJECTED')">保存</a-button>
          <a-button v-else class="button_right" type="primary" :loading="loadingBtn.DRAFT" @click="handleSubmit('DRAFT')">保存草稿</a-button>
          <a-button class="button_right" type="primary" :loading="loadingBtn.SUBMITTED" @click="handleSubmit('SUBMITTED')">提交</a-button>
          <a-button @click="handleActiveClose">关闭</a-button>
        </div>
        <div class="btn_box page-btn-right-top" v-else-if="!isConsultation">
          <print-button v-if="form.auditStatus == 3 && form.type == 2" button-text="审批表打印" :before-print-fn="printApprovalForm" />
          <print-button v-if="form.auditStatus == 3 && form.type !== 2" button-text="评价表打印" :before-print-fn="managementPrint" />
          <print-button v-if="form.auditStatus == 3" class="ml12" button-text="报审表打印" :before-print-fn="approvalDetailsPrint" />
          <a-button class="ml12" @click="handleActiveClose">关闭</a-button>
        </div>
      </a-spin>
      <DialogForm
        ref="dialogForm"
        :visible.sync="visible"
        :edit-model="editModelDialog"
        :form="initData"
        :header-title="editModelDialog == 'V' ? '查看新增清单' : editModelDialog == 2 ? '新增新增清单' : '编辑新增清单'"
        :width="800"
        :height="1100"
        :isEmit="false"
        :rules="rulesDialog"
        :form-list="formListDialog"
        @confirm="submitForm"
        :clearForm="true"
        :styles="{ width: '550px' }"
      />
    </a-form-model>
     <selectApprover :businessId="businessId"  :processConfig="setProcessConfig"></selectApprover>
  </base-breadcrumb>
</template>

<script>
import { updateAddListContract, addAddListContract, getAddListContract, managementPrint, approvalDetailsPrint, printApprovalForm } from '@/api/businessAffairs/addListContract' // api
import printButton from '@/components/BasePrintButton' // 打印
import BaseEditPage from '@/views/baseEditPage' // 编辑详情页基础配置
import SelectPersonModal from '@/components/SelectPersonModal'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import SelectPersonByProject from '@/components/Select/SelectPersonByProject'
import Selector from '@/components/Select/Selector'
import BSelect from '@/components/BComponents/BSelect'
// import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import SelectSubcontractorCode from '@/components/Select/SelectSubcontractorCode' // 分包商
import subcontract from '@/api/legal/branchContract/subcontract'
import { typeLabel, status } from './model.js'
import ExportExcel from '@/components/exportExcel/ExportExcel' // 导出
import DialogForm from '@/components/DialogForm' // 弹窗
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '新增清单项目',
    dataIndex: 'increaseProject',
    ellipsis: true
  },
  {
    title: '单位',
    dataIndex: 'unit',
    ellipsis: true
  },
  {
    title: '工程量',
    dataIndex: 'quantities',
    ellipsis: true
  },
  {
    title: '项目特征',
    dataIndex: 'projectCharacteristics',
    ellipsis: true
  },
  {
    title: '工作内容',
    dataIndex: 'jobContent',
    ellipsis: true
  },
  {
    title: '控制价(不含税)(元)',
    dataIndex: 'controlPrice',
    ellipsis: true
  },
  {
    title: '单价(不含税)(元)',
    dataIndex: 'unitPrice',
    ellipsis: true
  },
  {
    title: '合价(不含税)(元)',
    dataIndex: 'totalPrice',
    ellipsis: true
  },
  {
    title: '备注',
    dataIndex: 'remark',
    ellipsis: true
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '230px',
    scopedSlots: { customRender: 'operation' }
  }
]
const columnsLook = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '新增清单项目',
    dataIndex: 'increaseProject',
    ellipsis: true
  },
  {
    title: '单位',
    dataIndex: 'unit',
    ellipsis: true
  },
  {
    title: '工程量',
    dataIndex: 'quantities',
    ellipsis: true
  },
  {
    title: '项目特征',
    dataIndex: 'projectCharacteristics',
    ellipsis: true
  },
  {
    title: '工作内容',
    dataIndex: 'jobContent',
    ellipsis: true
  },
  {
    title: '控制价(不含税)(元)',
    dataIndex: 'controlPrice',
    ellipsis: true
  },
  {
    title: '单价(不含税)(元)',
    dataIndex: 'unitPrice',
    ellipsis: true
  },
  {
    title: '合价(不含税)(元)',
    dataIndex: 'totalPrice',
    ellipsis: true
  },
  {
    title: '备注',
    dataIndex: 'remark',
    ellipsis: true
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BaseEditPage(),
  components: {
    SelectPersonModal,
    SelectPersonByProject,
    SelectSubcontractorCode,
    ExportExcel,
    DialogForm,
    printButton
  },
  data() {
    this.columns = columns
    this.columnsLook = columnsLook
    return {
      loading: false, // 加载控件
      visible: false, //弹窗控件
      editModel: 0, // 操作状态:0 查看;1 编辑;2 新增
      editModelDialog: '0', //弹框操作状态:0 查看;1 编辑;2 新增
      form: { commercialInsertDetaileds: [],projectId:null}, // 表单
      updateList: [], //修改的表格数组
      initData: {},
      id: '',

      projectName: '',
      loadingBtn: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false,
        REJECTED: false
      },
      findCountQueryParam: {
        pageNo: 1,
        pageSize: 10000,
        query: {}
      },
      rules: {
        contractId: [{ required: true, message: '请选择' }],
        subcontractorScc: [{ required: true, message: '请选择' }],
        type: [{ required: true, message: '请选择' }],
        specialCause: [{ required: true, message: '请输入' }],
        comparison: [{ required: true, message: '请输入' }],
        increaseMoney: [{ required: true, message: '请输入' }],
        contractSettlementDeputy: [{ required: true, message: '请输入' }],
        telPhone: [{ required: true, message: '请输入' }],
      },
      rulesDialog: {
        increaseProject: [{ required: true, message: '请输入' }],
        unit: [{ required: true, message: '请输入' }],
        quantities: [{ required: true, message: '请输入' }],
        projectCharacteristics: [{ required: true, message: '请输入' }],
        jobContent: [{ required: true, message: '请输入' }],
        controlPrice: [{ required: true, message: '请输入' }],
        unitPrice: [{ required: true, message: '请输入' }],
        totalPrice: [{ required: true, message: '请输入' }]
      },
      loadData: () => {
        return new Promise((resolve, reject) => {
          console.log(this.form.commercialInsertDetaileds)
          resolve({
            data: this.form.commercialInsertDetaileds || []
          })
        })
      },

      init: false, // 初始化控件
      titles: ['新增清单或超额合同审批查看', '新增清单或超额合同审批编辑', '新增清单或超额合同审批新增'],
      importCheck: {
        新增清单项目: 'increaseProject',
        单位: 'unit',
        工程量: 'quantities',
        项目特征: 'projectCharacteristics',
        工作内容: 'jobContent',
        '控制价(不含税)(元)': 'controlPrice',
        '单价(不含税)(元)': 'unitPrice',
        '合价(不含税)(元)': 'totalPrice',
        备注: 'remark'
      },
        //获取流程配置值
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null

    }
  },
  props: {
    // 是否作为审批详情
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    isAudit: {
      immediate: true,
      handler(val) {
        if (val) {
          this.$nextTick(() => {
            this.editModel = 0
          })
        }
      }
    },
    'form.type':{
    immediate: true,
     async handler(val) {
      //类别为新增或补偿为‘commercial_insert_detailed’
      let config = val*1>1?'commercial_insert_detailed_1':'commercial_insert_detailed';
       //获取通过获取流程配置值
          this.processConfig = await this.$getConfigFn(config);
      }
    }
  },
 async mounted() {
    this.$route.meta.title = ['新增清单或超额合同审批查看', '新增清单或超额合同审批编辑', '新增清单或超额合同审批新增'][this.editModel]
    // 不为添加时请求详情
    if (this.editModel != 2) {
      this.getDetails()
    } else {
      this.form.projectId = this.$userInfo().currentPost.projectId;
      this.$nextTick(() => {
        // 默认映射联系人为登陆人
        this.form.applicantName = this.$userInfo().name
        this.form.applicantId = this.$userInfo().id
        this.form.updateTime = this.$dateFormat(new Date(), 'D')
        this.init = true
      })
    }
  },
  computed: {
    exportList() {
      let list = this.$clone(this.columns)
      list.pop()
      list.shift()
      return [
        {
          columns: list,
          datas: [{}]
        }
      ]
    },
    formListDialog() {
      return [
        {
          keyName: 'increaseProject',
          type: 'BaseInput',
          label: '新增清单项目',
          span: 24
        },
        {
          keyName: 'unit',
          type: 'BaseInput',
          label: '单位',
          span: 24
        },
        {
          keyName: 'quantities',
          type: 'BaseInput',
          label: '工程量',
          span: 24
        },
        {
          keyName: 'projectCharacteristics',
          type: 'BaseTextarea',
          label: '项目特征',
          span: 24
        },
        {
          keyName: 'jobContent',
          type: 'BaseTextarea',
          label: '工作内容',
          span: 24
        },
        {
          keyName: 'controlPrice',
          type: 'BaseInputNumber',
          label: '控制价(不含税)(元)',
          span: 24
        },
        {
          keyName: 'unitPrice',
          type: 'BaseInputNumber',
          label: '单价(不含税)(元)',
          span: 24
        },
        {
          keyName: 'totalPrice',
          type: 'BaseInputNumber',
          label: '合价(不含税)(元)',
          span: 24
        },
        {
          keyName: 'remark',
          type: 'BaseTextarea',
          label: '备注',
          span: 24
        }
      ]
    },
    formList() {
      return [
       {
          label: '所属单位',
          type: 'orgTree',
          keyName: 'projectId',
          rules: [{ required: true, message: '请选择项目名称', trigger: 'change' }],
          span: 16,
          isAutoSelectFirst: true,
          isNeedAuth:true ,
          checkStrictly: true,
          disabled: true,
          viewName: "viewName",
        },
        // {
        //   type: SelectSubCompany,
        //   keyName: 'branchCompanyId',
        //   label: '所属分公司',
        //   disabled: true,
        //   attrs: {
        //     isDefaultSelected: this.editModel == 2,
        //     autoSelected: this.editModel == 2
        //   }
        // },
        // {
        //   type: SelectProject,
        //   keyName: 'projectId',
        //   label: '所属项目',
        //   disabled: true,
        //   attrs: {
        //     isDefaultSelected: this.editModel == 2,
        //     autoSelected: this.editModel == 2,
        //     keyValue: 'branchCompanyId',
        //     isClear: this.editModel == 2,
        //     isEdit: this.editModel != 2,
        //     form: this.form
        //   },
        //   selectChange: (e) => {
        //     console.log(e)
        //     this.form.projectDeptId = e?.projectDeptId
        //   }
        // },
        {
          keyName: 'subcontractorName',
          type: 'a-input',
          disabled: true,
          label: '分包单位',
          placeholder: '自动带出',
          hidden:this.editModel !== 0,
        },
        {
          type: SelectSubcontractorCode,
          keyName: 'subcontractorScc',
          label: '分包单位',
          disabled: this.editModel == 0,
          hidden:this.editModel == 0,
          attrs: {
            keyValue: 'projectId',
            isClear: this.editModel == 2,
            isEdit: this.editModel != 2,
            form: this.form
          },
          selectChange: (e, b) => {
            this.$set(this.form, 'subcontractorName', e?.name)
            this.$set(this.form, 'contractId', undefined)
            this.$set(this.form, 'originalContractMoney', undefined)
          }
        },
          {
          keyName: 'contractName',
          type: 'a-input',
          disabled: true,
          label: '分包合同名称',
          placeholder: '自动带出',
          hidden:this.editModel !== 0,
        },
        {
          keyName: 'contractId',
          type: BSelect,
          disabled: this.editModel == 0,
          hidden:this.editModel == 0,
          label: '分包合同名称',
          attrs: {
            form: this.form,
            keyValue: 'subcontractorName',
            request: this.getNameList
          },
          selectChange: (e) => {
            //切换名称获取数据
            this.form.contractName = e.contractName
            this.form.originalContractMoney = e?.contractInTaxAmount / 10000
          }
        },
        {
          keyName: 'originalContractMoney',
          type: 'BaseInput',
          disabled: true,
          label: '原合同额(万元)'
        },

        {
          keyName: 'type',
          type: 'a-select',
          disabled: this.editModel == 0,
          label: '类别',
          data: typeLabel,
        },
        {
          keyName: 'increaseMoney',
          type: 'BaseInputNumber',
          disabled: this.editModel == 0,
          precision: 2,
          label: '本次增加金额(万元)'
        },
        {
          keyName: 'contractSettlementDeputy',
          type: 'BaseInput',
          disabled: this.editModel == 0,
          hidden: this.form?.type !== 2,
          label: '分包结算代表'
        },
        {
          keyName: 'telPhone',
          type: 'BaseInput',
          disabled: this.editModel == 0,
          hidden: this.form?.type !== 2,
          label: '联系电话'
        },
        {
          keyName: 'applicantName',
          type: 'BaseInput',
          disabled: true,
          label: '申请人'
        },
        {
          keyName: 'updateTime',
          type: 'a-date-picker',
          placeholder: '请选择日期',
          disabled: true,
          label: '填报时间',
          attrs: {
            valueFormat: 'YYYY-MM-DD'
          }
        },
        {
          keyName: 'specialCause',
          type: 'BaseTextarea',
          label: '特殊事由',

          disabled: this.editModel == 0,
          span: 24,
          attrs: {
            maxLength: 500
          }
        },
        {
          keyName: 'comparison',
          type: 'BaseTextarea',
          label: '总分包效益对比',
          disabled: this.editModel == 0,
          span: 24
        },
        {
          keyName: 'fileInfoList',
          type: 'uploadFile',
          label: '附件上传',
          disabled: this.editModel == 0,
          span: 24,
          businessCode: 'FACE16'
        }
      ]
    },
    formListHuiqian() {
      return [
        {
          keyName: 'buildPosition',
          type: 'BaseTextarea',
          label: '施工部位（范围、轴线、标高）',
          disabled: true,
          span: 24
        },
        {
          keyName: 'completeContent',
          type: 'BaseTextarea',
          label: '施工完成内容及工作量',
          disabled: true,
          span: 24
        },
        {
          keyName: 'contractProjectQuantity',
          type: 'BaseTextarea',
          label: '合同工程量',
          disabled: true,
          span: 24
        },
        {
          keyName: 'actualComplete',
          type: 'BaseTextarea',
          label: '实际完成工程量初审值',
          disabled: true,
          span: 24
        },
        {
          keyName: 'summationPaid',
          type: 'BaseTextarea',
          label: '累计已付工程款金额',
          disabled: true,
          span: 24
        },
      ]
    }
  },
  methods: {
    //选择单位
    selectOrg(val) {
        if (val && val.length) {
            this.form.branchComId = val[val.length - 2].orgId
        }
    },
    //获取项目详情
    getProjectInfo(e) {
        this.form.projectDeptId = e?.projectDeptId
    },
    // 打印
    managementPrint() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        managementPrint(data)
          .then((res) => {
            if (res.code == 0 || res.data.code === 0) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    // 打印
    approvalDetailsPrint() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        approvalDetailsPrint(data)
          .then((res) => {
            if (res.code == 0 || res.data.code === 0) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    // 打印
    printApprovalForm() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        printApprovalForm(data)
          .then((res) => {
            if (res.code == 0 || res.data.code === 0) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    /**
     * 导入
     */
    handleImport(e) {
      let form = []
      let that = this
      let messages = []
      console.log(e)
      for (let m in e) {
        let keys = e[m]
        let listItem = {}
        let msg = `第${Number(m) + 1}行：`
        let msgList = []
        // 校验excel的表头数量
        // console.log(e[m],e[m][index])
        // 校验excel的表头字段
        for (let i in this.importCheck) {
          let item = this.importCheck[i]
          if (!keys[i] && !Object.keys(keys).includes(i) && i != '备注') {
            msgList.push(`${i.replace(/\*/g, '')}不能为空`)
          } else {
            // 校验数字
            if ((item === 'controlPrice' || item === 'unitPrice' || item === 'totalPrice') && !this.isNumber(keys[i])) {
              msgList.push(`${i.replace(/\*/g, '')}格式为数字`)
            }
            if (item !== 'controlPrice' && item !== 'unitPrice' && item !== 'totalPrice') {
              listItem[item] = (keys[i] || '') + ''
              if (listItem[item].length > 300) {
                msgList.push(`${i.replace(/\*/g, '')}字数最多300`)
              }
            } else {
              listItem[item] = keys[i]
            }
          }
        }
        listItem.myId = this.randomString(8)
        msgList.length > 0 && messages.push(<div>{msg + msgList.join('，')}</div>)
        form.push(listItem)
      }
      console.log(form)
      if (messages.length > 0) {
        that.loadingImport = false
        let content = messages.map((item) => <div style="width:100%">{item}</div>)
        that.$warning({
          width: 800,
          title: '导入失败',
          content: content
        })
        return
      }
      this.form.commercialInsertDetaileds = this.form.commercialInsertDetaileds.concat(form)
      this.$refs.table.refresh(true)
    },
    /**
     * 生成随机字符串 + 时间戳作为唯一id
     */
    randomString(len) {
      len = len || 32
      let timestamp = new Date().getTime()
      /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
      let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
      let maxPos = $chars.length
      let randomStr = ''
      for (let i = 0; i < len; i++) {
        randomStr += $chars.charAt(Math.floor(Math.random() * maxPos))
      }
      return randomStr + timestamp
    },
    /**
     * 字符串/数字判断
     */
    isNumber(val) {
      let regPos = /^\d+(\.\d+)?$/ //非负浮点数
      let regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/ //负浮点数
      if (regPos.test(val) || regNeg.test(val)) {
        return true
      } else {
        return false
      }
    },
    /**
     * 表格新增
     */
    submitForm(e) {
      if (this.editModelDialog == '2') {
        e.myId = this.randomString(8)
        this.form.commercialInsertDetaileds.push(e)
      } else {
        this.form.commercialInsertDetaileds.forEach((i, idx) => {
          if (i.myId == e.myId) {
            this.form.commercialInsertDetaileds[idx] = e
          }
        })
      }

      this.visible = false
      this.$refs.table.refresh(true)
    },
    /**
     * 操作栏 type:0 新增;1 编辑
     */
    handleManage(type, record) {
      this.editModelDialog = type == '0' ? 'V' : type // 映射操作类型
      this.initData = type == '2' ? {} : record // 配置参数
      this.visible = true // 打开表单
    },
    async getNameList() {
      if (this.form.projectId && this.form.subcontractorName) {
        let req = {
          projectId:this.form.projectId,
          subSupplyCompany:this.form.subcontractorName
        }
        // this.findCountQueryParam.query.subSupplyCompany = this.form.subcontractorName
        return subcontract
          .getSubContractByScc(req).then((res) => {
            if (res.data?.length > 0) {
              res.data.map((item) => {
                item.name = item.contractName
                item.id = item.contractId
              })
            }
            return { code: 200, data: res.data }
          })
          .catch(() => {
            return { code: 200, data: [] }
          })
      }
      return { code: 200, data: [] }
    },
    // 删除
    handleRemove(data, idx) {
      this.form.commercialInsertDetaileds.splice(idx, 1)
      this.$refs.table.refresh(true)
    },

    getDetails() {
      this.loading = true

      getAddListContract({ id: this.id })
        .then((res) => {
          this.loading = false
          this.form = res.data
          this.$refs.table.loadData()
          this.$nextTick(() => {
            this.init = true
          })
        })
        .catch(() => {
          this.loading = false
        })
    },
    /**
     * 提交表单
     */
    validateForm() {
      let flag1 = true
      let flag2 = true
      this.$refs.ruleForm.validate((e) => {
        flag1 = e
      })
      if (this.form.type == 0 && this.form.commercialInsertDetaileds.length == 0) {
        this.$message.warning('请添加计划表数据')
        flag2 = false
        return false
      }
      if (flag1 && flag2) {
        return true
      } else {
        this.$message.warning("请填写完所有必填项信息")
        return false
      }
    },
    okSubmit(status) {
      this.setProcessConfig = null;
      this.loading = true
      this.loadingBtn[status] = true

      let form = this.$clone(this.form)
      if (status != 'REJECTED') {
        form.auditStatus = status == 'SUBMITTED' ? 1 : 0
      } else {
        form.auditStatus = 5
      }
      if (typeof form.year !== 'string') {
        form.year = this.$dateFormat(form.year, 'Y')
      }

      let api = [updateAddListContract, addAddListContract][this.editModel - 1] // 根据操作切换url地址
      this.submitApprovalConfirm(status == 'SUBMITTED' ?this.processConfig:6, (flag)=>{
        if(!flag) {
          this.loading = false
          this.loadingBtn[status] = false
          return
        }
      api(form)
        .then((res) => {
          this.loading = false
          this.loadingBtn[status] = false
          this.$message.success(status == 'SUBMITTED' ? '提交成功！' : '保存成功')
          //提交时，返回id
          if(status =='SUBMITTED') {
            //提交时，返回id
                this.businessId = res.data?.id || this.id;
                this.setProcessConfig = this.processConfig;
                return
            }else{
             this.$multiTab.close()
          }

        })
        .catch(() => {
          this.loadingBtn[status] = false
          this.loading = false
          this.$message.warning(err.data.message)
        })
      })
    },
    /**
     * 提交表单
     */
    handleSubmit(status) {
      if (status == 'SUBMITTED' && !this.validateForm()) {
        return
      }

      this.okSubmit(status)
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .form-item  {
  .ant-input:not([disabled]),
  .ant-select:not(.ant-select-disabled) .ant-select-selection,
  .ant-calendar-picker-input,
  .ant-input-number:not([disabled]),
  .ant-cascader-picker {
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
  .ant-input-disabled,
  .ant-input-number-disabled .ant-input-number-input,
  .ant-time-picker-input[disabled] {
    border-color: #d9d9d9 !important;
    background-color: #f5f5f5 !important;
  }
  .remark {
    .ant-input {
      border-color: inherit;
      background-color: initial;
    }
  }
}
</style>
